package com.wdc.deliveryrobot.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.wdc.deliveryrobot.R;

public class AddPointDialog {

    private Dialog dialog;

    private Button buttonOk,buttonCancel;

    private LinearLayout linearLayout,linearLayoutPoint;

    private EditText editTextInput,editTextMap;

    private TextView textView,textViewTop;

    private RadioGroup radioGroup;

    private WindowManager.LayoutParams layoutParams;

    public AddPointDialog(Context context){
        dialog = new Dialog(context);
        dialog.setContentView(R.layout.dialog_addpoint);
        buttonCancel = dialog.findViewById(R.id.cancel_button);
        editTextInput = dialog.findViewById(R.id.pointName);
        buttonOk = dialog.findViewById(R.id.ok_button);
        textView = dialog.findViewById(R.id.point_Name);
        textViewTop = dialog.findViewById(R.id.message);
        linearLayout = dialog.findViewById(R.id.map_floor);
        editTextMap = dialog.findViewById(R.id.map_text);
        radioGroup = dialog.findViewById(R.id.point);
        linearLayoutPoint = dialog.findViewById(R.id.point_set);
        dialog.setCancelable(false); // 设置为不可取消，除非明确调用取消
        // 设置 Dialog 的宽度和高度
        layoutParams = new WindowManager.LayoutParams();
        layoutParams.copyFrom(dialog.getWindow().getAttributes());
//        layoutParams.width = 450; // 或设置为具体的像素值
//        layoutParams.height = 250; // 或设置为具体的像素值
        // 设置 Dialog 的背景为圆角
        dialog.getWindow().setBackgroundDrawableResource(R.drawable.dialog_background);
        dialog.getWindow().setAttributes(layoutParams);
        dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

        buttonCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
    }

    public void setOkButtonClickListener(final View.OnClickListener listener) {
        buttonOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(v);
                }
                //dismiss();
            }
        });
    }

    public void dismiss() {
        dialog.dismiss();
//        if (onDismissListener != null) {
//            onDismissListener.onDismiss();
//        }
    }

    public void show() {
        View decorView = dialog.getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

        decorView.setSystemUiVisibility(uiOptions);

        dialog.show();

    }

    public boolean isEditNull(){
        String name = editTextInput.getText().toString().trim();
        if (name.isEmpty() || name == null){
            return true;
        }
        return false;
    }

    public boolean isMapNull(){
        String name = editTextMap.getText().toString().trim();
        if (name.isEmpty() || name == null){
            return true;
        }
        return false;
    }

    public String getEditMap(){
        return editTextMap.getText().toString().trim();
    }

    public String getEditText(){
        return editTextInput.getText().toString().trim();
    }

    public void setMessage(String message){
        textView.setText(message);
    }

    public void setHint(String message){
        editTextInput.setHint(message);
    }

    public void setTop(String message){
        textViewTop.setText(message);
    }

    //设置选中楼层不可见
    public void mapSet(){
        linearLayout.setVisibility(View.GONE);
    }

    //设置点位类型不可见
    public void pointSet(){
        linearLayoutPoint.setVisibility(View.GONE);
    }

    public Integer isCheck(){
        int k = radioGroup.getCheckedRadioButtonId();
        if (k == R.id.radioOne){
            return 1;
        }else if (k == R.id.radioTwo){
            return 2;
        }else if (k == R.id.radioThree){
            return 3;
        }else if (k == R.id.radioFour){
            return 4;
        }else {
            return -1;
        }
    }

    public void setWidth(int width,int height){
        layoutParams.width = width; // 或设置为具体的像素值
        layoutParams.height = height; // 或设置为具体的像素值
    }

}
